package com.base.data.controller;


import com.base.common.model.bean.KeyValue;
import com.base.data.annotations.Select;
import com.base.data.annotations.Update;

import java.util.List;

public interface SQLMapper {

    /**
     *
     */
    @Select("        SELECT " +
            "            * " +
            "        FROM " +
            "            t_all_field " +
            "        WHERE table_name= 't_instrument_info' AND is_show=1  " +
            "          AND (   field_eng_name = 'serialNumber'" +
            "           OR field_eng_name = 'deviceClassify'" +
            "           OR field_eng_name = 'equipmentTesting'" +
            "           OR field_eng_name = 'number' " +
            "           OR field_eng_name = 'name' " +
            "           OR field_eng_name = 'department' " +
            "           OR field_eng_name = 'deviceStatus' " +
            "           OR field_eng_name = 'calculateGrade' " +
            "           OR field_eng_name = 'planTime' " +
            "           OR field_eng_name = 'calculateTime' " +
            "           OR field_eng_name = 'calculateCycle' " +
            "           OR field_eng_name = 'calculateRules' " +
            "           OR field_eng_name = 'lastReport' " +
            "           OR field_eng_name = 'institution' )")
    List<Object> measurementSelectLeftFields();

    /**
     *
     */
    @Select("SELECT tif.title_name,tif.field_eng_name,tif.sort\n" +
            "        FROM t_all_field tif\n" +
            "        WHERE table_name='t_instrument_info' AND sort!=0 AND is_show=1\n" +
            "            AND field_eng_name!='serialNumber'\n" +
            "            AND field_eng_name!='deviceClassify'\n" +
            "            AND field_eng_name!='equipmentTesting'\n" +
            "            AND field_eng_name!='number'\n" +
            "            AND field_eng_name!='name'\n" +
            "            AND field_eng_name!='department'\n" +
            "            AND field_eng_name!='deviceStatus'\n" +
            "            AND field_eng_name!='calculateGrade'\n" +
            "            AND field_eng_name!='planTime'\n" +
            "            AND field_eng_name!='calculateTime'\n" +
            "            AND field_eng_name!='calculateCycle'\n" +
            "            AND field_eng_name!='calculateRules'\n" +
            "            AND field_eng_name!='lastReport'\n" +
            "            AND field_eng_name!='institution'\n" +
            "        ORDER BY sort")
    List<Object> measurementSelectAllFields();


    /**
     * <p>
     * 根据resource_number查找资源
     */

    @Select("select resource_number,resource_location,encrypt_key from t_resource_media where is_del=1 and resource_number in (%1$s)  ")
    List<KeyValue<String, String, String>> selectResourceByNumber(String resource_number);

    /**
     * <p>
     * 根据resource_number删除资源
     */
    @Update("update t_resource_media set is_del=2 where  resource_number in (%1$s) ")
    void deleteResourceByNumber(String resource_numbers);

    /**
     * <p>
     * 根据resource_location删除资源
     */
    @Update("update t_resource_media set is_del=2 where  resource_location in (%1$s) ")
    void deleteResourceByLocation(String resource_location);

    /**
     * 获取部门管理的数据源
     *
     * @return
     */
    @Select("select a.*\n" +
            ",(select name from t_sys_dept  where a.dept_rele_parent_id=dept_rele_id) as dept_patent_name\n" +
            ", b.type_name                                                               as type_per_number\n" +
            " from t_sys_dept a \n" +
            "left join t_dept_dept_type c on(a.dept_number=c.dept_number)\n" +
            "left join t_dept_type b on(c.type_per_number=b.type_per_number)" +
            " where a.is_del=1  order by a.dept_rele_parent_id")
    List<Object> getDepartmentType();

    /**
     * 更新部门的中间表
     */
    @Update("update t_dept_dept_type set type_per_number='%1$s'  where dept_number='%2$s'")
    void updateDepartmentTypeType(String type_per_number, String dept_number);


    @Select("select a.* \n" +
            "            ,(select name from t_sys_dept  where a.dept_rele_parent_id=dept_rele_id) as dept_patent_name \n" +
            "            , b.type_name                                                               as type_per_number \n" +
            "             from t_sys_dept a  \n" +
            "            left join t_dept_dept_type c on(a.dept_number=c.dept_number) \n" +
            "            left join t_dept_type b on(c.type_per_number=b.type_per_number) \n" +
            "            where a.is_del=1 and  a.%1$s = %2$s \n" +
            "            order by a.dept_rele_parent_id")
    Object getDepartmentType(String whereField, String whereValue);

    /**
     * 获取部门ID
     *
     * @return
     */
    @Select("select  max(dept_rele_id) from t_sys_dept")
    Integer getMaxDeptId();

}
